package com.ssy.lingxi.member.merchant.controller.mobile;

import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.*;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.CountryAreaCodeNameVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.CountryCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberConfigGroupVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.MobileRegisterVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordByEmailCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.request.ResetPasswordBySmsCodeVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberRegisterResultVO;
import com.ssy.lingxi.member.merchant.model.vo.login.response.MemberRegisterTypeMenuVO;
import com.ssy.lingxi.member.merchant.service.mobile.IMobileRegisterService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu App - 会员注册相关接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-12-02
 */
@RestController
@RequestMapping("/member/mobile/register")
public class MobileRegisterController {

    @Resource
    private IMobileRegisterService mobileRegisterService;

    /**
     * 获取国家代码和手机号码位数
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/country/list", method = RequestMethod.GET)
    public Wrapper<List<CountryCodeVO>> listCountryCode(@RequestHeader HttpHeaders headers) {
        return mobileRegisterService.listCountryCode(headers);
    }

    /**
     * “账号注册” - 检查手机号码是否被注册使用
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 检查结果
     */
    @RequestMapping(value = "/phone/check", method = RequestMethod.GET)
    public Wrapper<Void> checkPhoneRegistered(@RequestHeader HttpHeaders headers, @Valid PhoneVO phoneVO) {
        return mobileRegisterService.checkPhoneRegistered(headers, phoneVO);
    }

    /**
     * 检查邮箱是否被注册使用
     * @param headers Http头部信息
     * @param emailVO 邮箱
     * @return 检查结果
     */
    @RequestMapping(value = "/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkEmailRegistered(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailVO emailVO) {
        return mobileRegisterService.checkEmailRegistered(headers, emailVO);
    }

    /**
     * 发送注册时短信验证码
     * @param headers Http头部信息
     * @param phoneVO 接口参数
     * @return 发送结果
     */
    @RequestMapping(value = "/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendRegisterSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return mobileRegisterService.sendRegisterSmsCode(headers, phoneVO);
    }

    /**
     * “手机号找回密码” - 检查手机号码是否存在
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 检查结果
     */
    @RequestMapping(value = "/psw/phone/check", method = RequestMethod.POST)
    public Wrapper<Void> checkPhoneExistsByMobile(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return mobileRegisterService.checkPhoneExistsByMobile(headers, phoneVO);
    }

    /**
     * 发送手机号找回密码时的短信验证码
     * @param headers Http头部信息
     * @param phoneVO 手机号码
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/sms", method = RequestMethod.POST)
    public Wrapper<Void> sendResetPasswordSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneVO phoneVO) {
        return mobileRegisterService.sendResetPasswordSmsCode(headers, phoneVO);
    }

    /**
     * 校验手机号找回密码时的短信验证码是否正确
     * @param headers Http头部信息
     * @param phoneSmsVO 手机号码、验证码
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/sms/check", method = RequestMethod.POST)
    public Wrapper<Void> checkResetPasswordSmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid PhoneSmsVO phoneSmsVO) {
        return mobileRegisterService.checkResetPasswordSmsCode(headers, phoneSmsVO);
    }

    /**
     * 根据短信验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/reset/sms", method = RequestMethod.POST)
    public Wrapper<Void> resetPasswordBySmsCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid ResetPasswordBySmsCodeVO codeVO) {
        return mobileRegisterService.resetPasswordBySmsCode(headers, codeVO);
    }

    /**
     * 发送邮箱找回密码时的邮件
     * @param headers Http头部信息
     * @param emailVO 邮箱地址
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/email", method = RequestMethod.POST)
    public Wrapper<Void> sendResetPasswordEmail(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailVO emailVO) {
        return mobileRegisterService.sendResetPasswordEmail(headers, emailVO);
    }

    /**
     * 校验邮箱找回密码时的邮件验证码是否正确
     * @param headers Http头部信息
     * @param emailVO 邮箱地址
     * @return 发送结果
     */
    @RequestMapping(value = "/psw/email/check", method = RequestMethod.POST)
    public Wrapper<Void> checkResetPasswordEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid EmailSmsVO emailVO) {
        return mobileRegisterService.checkResetPasswordEmailCode(headers, emailVO);
    }

    /**
     * 根据邮箱验证码重设密码
     * @param headers Http头部信息
     * @param codeVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/reset/email", method = RequestMethod.POST)
    public Wrapper<Void> resetPasswordByEmailCode(@RequestHeader HttpHeaders headers, @RequestBody @Valid ResetPasswordByEmailCodeVO codeVO) {
        return mobileRegisterService.resetPasswordByEmailCode(headers, codeVO);
    }

    /**
     * 注册页面 - 获取会员类型、业务类型
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/type", method = RequestMethod.GET)
    public Wrapper<List<MemberRegisterTypeMenuVO>> getRegisterTypeMenu(@RequestHeader HttpHeaders headers) {
        return mobileRegisterService.getRegisterTypePageContent(headers);
    }

    /**
     * 注册页面 - 获取完善会员资料页面内容
     * @param headers Http头部信息
     * @param detailVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public Wrapper<List<MemberConfigGroupVO>> getRegisterDetailMenu(@RequestHeader HttpHeaders headers, MemberDetailVO detailVO) {
        return mobileRegisterService.getRegisterDetailPageContent(headers, detailVO);
    }

    /**
     * 注册页面 - 查询省列表
     * @return 查询结果
     */
    @RequestMapping(value = "/province", method = RequestMethod.GET)
    public Wrapper<List<CountryAreaCodeNameVO>> listProvince(@RequestHeader HttpHeaders headers) {
        return mobileRegisterService.listProvince(headers);
    }

    /**
     * 注册页面 - 根据省编码，查询市列表
     * @param codeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/city", method = RequestMethod.GET)
    public Wrapper<List<CountryAreaCodeNameVO>> listCitiesByProvinceCode(@RequestHeader HttpHeaders headers, @Valid CountryAreaCodeVO codeVO) {
        return mobileRegisterService.listCitiesByProvinceCode(headers, codeVO);
    }


    /**
     * 注册页面 - 根据市编码，查询区列表
     * @param codeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/district", method = RequestMethod.GET)
    public Wrapper<List<CountryAreaCodeNameVO>> listDistrictsByCityCode(@RequestHeader HttpHeaders headers, @Valid CountryAreaCodeVO codeVO) {
        return mobileRegisterService.listDistrictsByCityCode(headers, codeVO);
    }

    /**
     * 会员注册
     * @param headers Http头部信息
     * @param registerVO 接口参数
     * @return 注册结果
     */
    @RequestMapping(value = "", method = RequestMethod.POST)
    public Wrapper<MemberRegisterResultVO> registerMember(@RequestHeader HttpHeaders headers, @RequestBody @Valid MobileRegisterVO registerVO) {
        return mobileRegisterService.registerPlatformMember(headers, registerVO);
    }
}
